﻿@page "/So/SaleReturnDetail/Edit"
@using nERP.ViewModel.So.SaleReturnDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.SaleReturnId" Items="AllSaleReturns" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g0d08271f818141e8a2f97cd344f8a3a5" />
            <BootstrapInput @bind-Value="@Model.Entity.SaleReturnDetailCode" />
            <Select @bind-Value="@Model.Entity.SaleOutWarehouseDetailId" Items="AllSaleOutWarehouseDetails" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g92bb0f471fb24c4995ee0d3c8b1ff127" />
            <Select @bind-Value="@Model.Entity.SaleId" Items="AllSales" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gf025286538a142fd920549614b7bd72d" />
            <Select @bind-Value="@Model.Entity.SaleDetailId" Items="AllSaleDetails" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g0f8abcee4f0842f3ad31e5deedaa9e3c" />
            <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g2ae1c8a3763f409c8d849f5f46dbfd8e" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsName" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit" />
            <BootstrapInput @bind-Value="@Model.Entity.ReturnNumber" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.UnitPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.DiscountPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxRate" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxUnitPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalTaxPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SaleReturnDetailVM Model = new SaleReturnDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/So/SaleReturnDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSaleReturns = new List<SelectedItem>();
    private List<SelectedItem> AllSaleOutWarehouseDetails = new List<SelectedItem>();
    private List<SelectedItem> AllSales = new List<SelectedItem>();
    private List<SelectedItem> AllSaleDetails = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSaleReturns = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleReturns");
        AllSaleReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleOutWarehouseDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleOutWarehouseDetails");
        AllSaleOutWarehouseDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSales = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleDetails");
        AllSaleDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<SaleReturnDetailVM>($"/api/So/SaleReturnDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
